// JavaScript Document
//支持Enter键登录
document.onkeydown = function (e) {
    if ($(".bac").length == 0) {
        if (!e) e = window.event;
        if ((e.keyCode || e.which) == 13) {
            var obtnLogin = document.getElementById("submit_btn")
            obtnLogin.focus();
        }
    }
}
$(function () {
    $("#j_remember").attr("checked","checked");
    //记住密码功能
    $.ajax({
        type: 'post',
        dataType: 'Json',
        url: '/Login/GetCookieUser',
        success: function (data) {
            $("#username").val(data.name);
            $("#password").val(data.passwd);
        }
    });

    //登录事件
    $("#submit_btn").click(function () {
        if ($("#username").val() == "") {
            show_err_msg("请填写用户名");
        } else if ($("#password").val() == "") {
            show_err_msg("请填写密码");
        } else {
            $.ajax({
                type: 'post',
                dataType: 'Json',
                url: '/Login/Login',
                async: false,
                data: $("#login_form").serialize(),
                success: function (data) {
                    if (data.result) {
                        window.location.href = "/index.html"
                    } else {
                        $("#username").val("");
                        $("#password").val("");
                        show_err_msg(data.data);
                    }
                }
            });
        }
    });

});